package com.epidata.exam.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Table
@Entity
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ReciboDeSueldo implements Serializable,Comparable<ReciboDeSueldo> {
	/** Default value included to remove warning. Remove or modify at will. **/
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	private Long id;


	@JoinColumn(name="OWNER_ID")
	@ManyToOne(cascade = {CascadeType.ALL})
	@XmlTransient
	private Employee owner;

	@NotNull
	private BigDecimal importe;

	@Temporal(TemporalType.DATE)
	private Date fechaCobro;



	public ReciboDeSueldo() {
		super();
	}

	public ReciboDeSueldo(Employee owner, BigDecimal importe,
			Date fechaCobro) {
		super();
		this.owner = owner;
		this.importe = importe;
		this.fechaCobro = fechaCobro;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Employee getOwner() {
		return owner;
	}

	public void setOwner(Employee owner) {
		this.owner = owner;
	}

	public BigDecimal getImporte() {
		return importe;
	}

	public void setImporte(BigDecimal importe) {
		this.importe = importe;
	}

	public Date getFechaCobro() {
		return fechaCobro;
	}

	public void setFechaCobro(Date fechaCobro) {
		this.fechaCobro = fechaCobro;
	}

	@Override
	public int compareTo(ReciboDeSueldo other) {
		int compare = 0;
		if(other != null){
			if(id != null){
				compare = this.id.compareTo(other.id);
			}else if(fechaCobro != null){
				compare = this.fechaCobro.compareTo(other.fechaCobro);
			}
		}
		return compare;
	}

	@Override
	public String toString() {
		return "ReciboDeSueldo [id=" + id + ", owner=" + owner + ", importe="
				+ importe + ", fechaCobro=" + fechaCobro + "]";
	}

}